how does a capacitor works